package com.acme.logging;

import java.util.logging.*;

/**
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */

public class MyClass {
    private final static String LOG_FILE_NAME = "lab21/src/test/resources/log.xml";

    public static void main(final String args[]) {
        try {
            Logger logger = Logger.getLogger("LoggingExample1");

            LogManager logManager = LogManager.getLogManager();
            logManager.addLogger(logger);

            logger = logManager.getLogger("LoggingExample1");
            if (logger == null) {
                System.out.println("There is no such logger");
                System.exit(1);
            }

            FileHandler fileHandler = new FileHandler(LOG_FILE_NAME);
            fileHandler.setFormatter(new XMLFormatter());
            fileHandler.setFilter(new MyFilter());

            ConsoleHandler consoleHandler = new ConsoleHandler();

            logger.addHandler(fileHandler);
            logger.addHandler(consoleHandler);
            logger.setLevel(Level.FINEST);

            logger.log(Level.INFO, "test lod level info");
            logger.log(Level.SEVERE, "test log level severe");
            logger.log(Level.WARNING, "test log level warning");
            logger.log(Level.CONFIG, "test log level config");
            logger.log(Level.FINE, "test log level fine");
            logger.log(Level.FINER, "test log level finer");
            logger.log(Level.FINEST, "test log level finest");

            fileHandler.close();
            consoleHandler.close();

        } catch (Exception e) {
            System.out.println("Exception thrown: " + e);
            e.printStackTrace();
        }
    }
}